package com.ruoyi.religion.sdk;



import com.ruoyi.religion.lib.NetDEVSDKLib;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Common {

	public static String timeStamp2Date(String seconds,String format) {
		if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
			return "";
		}
		if(format == null || format.isEmpty()) format = "yyyy-MM-dd HH:mm:ss";
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(new Date(Long.valueOf(seconds+"000")));
	}

	public static String utfToString(byte[] data) {
		try {
			int length = 0;
			for (int i = 0; i < data.length; ++i) {
				if (data[i] == 0) {
					length = i;
					break;
				}
			}
			return new String(data, 0, length, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			return "";
		}
	}


	public static String DevideStatusToString(int nStatus) {
		String strStatus = "";
		switch(nStatus){
			case NetDEVSDKLib.NETDEV_CHANNEL_STATUS_E.NETDEV_CHL_STATUS_OFFLINE:
				strStatus = "offline";
				break;
			case NetDEVSDKLib.NETDEV_CHANNEL_STATUS_E.NETDEV_CHL_STATUS_ONLINE:
				strStatus = "online";
				break;
			case NetDEVSDKLib.NETDEV_CHANNEL_STATUS_E.NETDEV_CHL_STATUS_UNBIND:
				strStatus = "unbind";
				break;
			default:
				strStatus = "INVALID";
				break;
		}
		return strStatus;
	}

}
